//组织选择
import React from 'react';
import { message } from 'antd';
import { PopupSelection } from '@/components/el/ItemComponent';
import { omit } from 'ramda';
import request from '@/utils/request';
interface Props {
  value?: any;
  onChange?: Function;
  paramData?: any;
  buType?: any;
  disabledFormItems?: any;
  hiddenFormItems?: any;
}
interface State {
  popupSelection: any;
}
// 在此处组装所有的数据
class PurcOrgPopupSelection extends React.Component<Props, State> {
  static defaultProps = {
    paramData: {},
    buType: 'PURC_BU',
    disabledFormItems: [],
    hiddenFormItems: []
  };
  constructor(props) {
    super(props);
    this.state = {
      popupSelection: null // 通过ref获取inputValue   popupSelection.state.inputValue
    };
  }
  componentDidMount() {}
  onRef = (ref) => {
    this.setState({
      popupSelection: ref
    });
  };
  onRequest = async (data) => {
    return request(`/yst-support/org/component/bu/subset/paging`, {
      method: 'post',
      query: {
        buType: this.props.buType,
        ...data,
        orders: [{ asc: false, column: 'createTime' }],
        ...this.props.paramData
      }
    });
  };
  render() {
    return (
      <>
        <PopupSelection
          overLayWidth={800}
          rowKey='id'
          modalTitle={
            this.props?.buType === 'PURC_BU'
              ? '请选择采购组织'
              : this.props?.buType === 'DEPT'
              ? '请选择部门组织'
              : ''
          }
          tableProxy={{
            request: this.onRequest,
            errCallBack: (res) => {
              message.error(res.msg || '操作失败');
            },
            props: {
              success: 'success',
              result: 'data.records',
              total: 'data.total'
            },
            autoLoad: true
          }}
          modalTableColumns={[
            {
              title: '组织编码',
              dataIndex: 'buCode',
              width: 100
            },
            {
              title: '组织名称',
              dataIndex: 'buName',
              width: 160,
              ellipsis: true
            },
            {
              title: '组织类型',
              dataIndex: 'buTypeName',
              align: 'center',
              width: 140
            },
            {
              title: '公司编码',
              dataIndex: 'ouCode',
              width: 100
            },
            {
              title: '公司名称',
              dataIndex: 'ouName',
              width: 160,
              ellipsis: true
            }
          ]}
          searchFormProps={{
            items: [
              {
                title: '组织',
                name: 'buCodeName',
                span: 8,
                formOption: {
                  type: '$input',
                  props: {
                    placeholder: '请输入组织编码或名称'
                  }
                }
              },
              {
                title: '公司',
                name: 'ouId',
                span: 8,
                hidden: this.props.hiddenFormItems.indexOf('ouId') !== -1,
                formOption: {
                  type: '$mg-select-ou',
                  props: {
                    placeholder: '请选择公司',
                    disabled:
                      this.props.disabledFormItems.indexOf('ouId') !== -1
                  }
                }
              }
            ]
          }}
          needModal={true}
          onRef={this.onRef}
          {...omit(
            ['searchFormProps', 'columns', 'modalTableColumns', 'tableProxy'],
            this.props
          )}
        />
      </>
    );
  }
}
export default PurcOrgPopupSelection;
